﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Text;
using System.Threading;
using System.Runtime.InteropServices;

namespace PrintingManagerSystem
{
    static class Program
    {

        public static EventWaitHandle ewh;
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            bool createNew;
            ewh = new EventWaitHandle(false, EventResetMode.AutoReset, "DA40575C-C9D7-4527-A6F4-0A90F5DE0419", out createNew);
            //var curretProcess = System.Diagnostics.Process.GetCurrentProcess();
            //System.Threading.Mutex mutex = new Mutex(true, curretProcess.ProcessName, out createNew);
            
            if (!createNew)
            {
                ewh.Set();
                Environment.Exit(1);
                return;
            }
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }
            catch (Exception e)
            {
                PMS.Log.Logger.Error(e);
                MessageBox.Show("软件中发生不可预料的错误，请在点击确定后重启软件。");
                Environment.Exit(1);
            }
        }
    }
}
